<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>打卡记录列表</title>
    <script type="text/javascript">

      Ext.onReady(function(){

        var recordDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: 100
          },
          proxy: new Ext.data.HttpProxy({
            url: '/checkrecord/getCheckrecords?train_task_id=<%= params[:trainTaskId] %>'
          }),
          autoLoad:true,
          reader:new Ext.data.JsonReader({
            totalProperty: 'total',
            root:'checkrecord'
          },[
            {name: 'worker_name'},
            {name: 'team_name'},
            {name: 'check_in_time'},
            {name: 'check_out_time'},
            {
              name:'work_time',
              convert:function(v,record){
                if(record.check_out_time==null){
                  return ''
                }else{
                  return Math.floor((new Date(record.check_out_time)-new Date(record.check_in_time))/60000)
                }

              }
            },
            {name: 'dynamic_check_in_time'},
            {name: 'dynamic_check_out_time'},
            {
              name:'dynamic_work_time',
              convert:function(v,record){
                if(record.dynamic_check_out_time==null){
                  return ''
                }else{
                  return Math.floor((new Date(record.dynamic_check_out_time)-new Date(record.dynamic_check_in_time))/60000)
                }

              }
            }
          ])
        });
        var recordSM = new Ext.grid.CheckboxSelectionModel();
        var recordCM = new Ext.grid.ColumnModel([
          new Ext.grid.RowNumberer(),
          recordSM,
          {header:'姓名',sortable:true,dataIndex:'worker_name',width:80},
          {header:'组队',dataIndex: 'team_name',width:200},
          {header:'静态开始时间',sortable:true,dataIndex: 'check_in_time',renderer: Ext.util.Format.dateRenderer('m-d H:i'),width:100},
          {header:'静态结束时间',sortable:true,dataIndex: 'check_out_time',renderer: Ext.util.Format.dateRenderer('m-d H:i'),width:100},
          {header: '<center>静态<br/>工作时长</center>',width:65,sortable:true,dataIndex:'work_time'},
          {header:'动态开始时间',sortable:true,dataIndex: 'dynamic_check_in_time',renderer: Ext.util.Format.dateRenderer('m-d H:i'),width:100},
          {header:'动态结束时间',sortable:true,dataIndex: 'dynamic_check_out_time',renderer: Ext.util.Format.dateRenderer('m-d H:i'),width:100},
          {header: '<center>动态<br/>工作时长</center>',width:65,sortable:true,dataIndex:'dynamic_work_time'},
        ]);

        var recordGrid =  new Ext.grid.GridPanel({
          ds: recordDS,
          cm: recordCM,
          sm: recordSM,
          width: 830,
          height: 497,
          iconCls: 'icon-grid',
          bbar: new Ext.PagingToolbar({
            pageSize: 100,
            store: recordDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          }),
          tbar: ['-',{
              text: '下载打卡信息',
              iconCls: 'disk',
              handler: function(){
                var path="/checkrecord/printRecord?train_task_id=<%= params[:trainTaskId] %>"
                window.open(path,'_blank','width=1,height=1,toolbar=no,menubar=no,location=no');
              }
            }
          ]
        });

        //总的panel
        var workbenchPanel = new Ext.Panel({
          width: screenWidth-180,
          frame:true,
          layout:'table',
          layoutConfig: {columns:1},
          defaults:{margins:'5 5 5 5'},
          items:[recordGrid]
        });
        
        workbenchPanel.render('recordList');
      })
    </script>
  </head>
  <body>
    <div id="recordList"></div>
  </body>
</html>
